package comparisons

import "jvmgo/ch08/instructions/base"
import "jvmgo/ch08/rtda"

/*
    比较两个引用值
 */

//ref1 == ref2
type IF_ACMPEQ struct {
    base.BranchInstruction
}

func (self *IF_ACMPEQ) Execute(frame *rtda.Frame) {
    if _acmp(frame) {
        base.Branch(frame, self.Offset)
    }
}

//ref1 != ref2
type IF_ACMPNE struct {
    base.BranchInstruction
}

func (self *IF_ACMPNE) Execute(frame *rtda.Frame) {
    if !_acmp(frame) {
        base.Branch(frame, self.Offset)
    }
}

func _acmp(frame *rtda.Frame) bool {
    stack := frame.OperandStack()
    ref2 := stack.PopRef()
    ref1 := stack.PopRef()
    return ref1 == ref2
}
